package com.example.yunifang.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.example.yunifang.R;
import com.example.yunifang.ZhuWebActivity;
import com.example.yunifang.bean.HeaderViewPagerBean.Data.Ad1;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

public class Fragment1MyPageAdapter extends PagerAdapter {

	ArrayList<Ad1> data;
	Context context;
	
	public Fragment1MyPageAdapter(ArrayList<Ad1> data, Context context) {
		super();
		this.data = data;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return Integer.MAX_VALUE;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		// TODO Auto-generated method stub
		
		container.removeView((View)object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		// TODO Auto-generated method stub
		ImageView imageView=new ImageView(context);
		imageView.setScaleType(ScaleType.FIT_XY);
		ImageLoader imageLoader = ImageLoader.getInstance();
		imageLoader.init(ImageLoaderConfiguration.createDefault(context));
		imageLoader.displayImage(data.get(position%data.size()).image, imageView);
		container.addView(imageView);
		imageView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(context,ZhuWebActivity.class);
				String str=data.get(position%data.size()).ad_type_dynamic_data;	
				intent.putExtra("str", str);
				context.startActivity(intent);
				((Activity) context).overridePendingTransition(R.anim.outactivity, R.anim.inactivity);
			}
		});
		return imageView;
	}


	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		// TODO Auto-generated method stub
		return arg0==arg1;
	}

}
